class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            one:1,
        };
    }









    componentDidMount() {
        if (Constant.SWITCH_VCONSOLE) {
            new VConsole();
        }

        //  console.log(liststr?'1':'2','liststr');
        // let list = JSON.parse(localStorage.getItem('orderlist')) || []
        // console.log(list, 'list');

        // this.setState({ list }, () => {
        //     this.getamount()
        // })
        // this.getdata()

    }

    pay(size) {
        let { openid, amount } = this.state;
        praypay(openid, Number(amount) * 100, size, res => {
            console.log(res, 'resres');
            let data = JSON.parse(res.ret)
            this.requestpay(data)
        })

    }

    requestpay(data) {
        function onBridgeReady() {

            let sign = md5(`appId=wxa29d77bb2e0c40bb&nonceStr=${data.nonce_str}&package=${data.package}&signType=MD5&timeStamp=${data.timeStamp}&key=Y3A7lWq2Xsd7ScCTSp8QUqLiWELxHCl7`).toUpperCase()
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                "appId": "wxa29d77bb2e0c40bb",     //公众号ID，由商户传入     
                "timeStamp": data.timeStamp,         //时间戳，自1970年以来的秒数     
                "nonceStr": data.nonce_str, //随机串     
                "package": data.package,
                "signType": "MD5",         //微信签名方式：     
                "paySign": sign //微信签名 
            },

                function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {

                        // 使用以上方式判断前端返回,微信团队郑重提示：
                        //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                    }
                });
        }
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }
    }



    inputbz(e) {
        this.setState({ desc: e.target.value })
    }

    clear() {
        var b = confirm('确定要清空吗')
        if (b) {
            localStorage.removeItem('orderlist')
            this.setState({ list: [], desc: '', amount: 0 })
        }
    }

    gopay() {
        let { sizeid, openid } = this.state;
        if (sizeid == '' || sizeid == '请选择') {
            alert('请先选择尺寸')
        } else {

            canbuy(openid, res => {
                if (res.data == true) {
                    this.pay(sizeid)
                } else {
                    alert('请勿重复购买')
                }

            })
            // 
        }

    }

    selectchange(e) {
        let { value } = e.target
        this.setState({ sizeid: value })
    }

    selectchange1(e) {
        let { value } = e.target, { amount, allprice } = this.state;
        if (value == 0) {
            amount = 610
        } if (value == -1) {
            amount = 300
        } if (value == 1) {
            amount = 835
        }
        this.setState({ cpid: value, amount })
    }


    render() {
        let { one, two, three, four, sizeid, cphtml, cpid } = this.state;
        //  console.log(sizehtml, 'sizehtml');
        return (
            <div id="app">
                <img onClick={()=>{
                    window.location.href='./main.html'
                }}  className="bg" src="./src/hdsm_bg.png" alt="" />
                {/* <img className="close" src="./src/close.png" alt="" /> */}
               
                {/* <img src="./src/main_2.png" alt="" />
                <img src="./src/main_3.png" alt="" /> */}

            </div>
        )
    }
}

ReactDOM.render(
    <div>
        {/* <TopLine /> */}
        <div id='body'>
            {/* <Tabbar index='1' /> */}
            <Main />
        </div>
    </div>
    // <Barrage />
    , $('.container')[0]
)